﻿using UnityEngine;
using System.Collections;
using Dict.DataModel;

namespace Room
{
    public class RCAIFish : RCAIBase
    {
        public RCAIFish(RoomCharactor owner)
            : base(owner)
        {
            type = AIType.Fish;
        }
        
        TableFieldResourcePos fishPos;
        float r;
        RoomCharactor player;
        
        public void Init(TableFieldResourcePos fishPos)
        {
            this.fishPos = fishPos;
            this.r = (float)fishPos.r;
            this.player = owner.charactorManager.GetSelfCharactor();  
        }

        float distance = 10f;
        float delay = 20f;
        float timer = 20f;

        public override void Tick()
        {
            if (player != null)
            {
                var dis = Vector3.Distance(owner.transform.position, player.transform.position);
                if (dis <= r)
                {
                    var ui = owner.ui as RCUIFish;
                    ui.ShowButton();
                }
                else
                {
                    owner.ui.HideButton();
                }
                
                if (dis < distance )
                {
                    timer += Time.deltaTime;
                    if(timer >= delay)
                    {
                        timer = 0f;
                        var room = Room.RoomManager.currentRoom as RoomField;
                        if(room!=null)
                        {
                            var netManager = (RoomNetField)room.netManager;
                            netManager.SendResourceCheck(fishPos.posId);
                        }
                    }
                }
            }
        }
    }
}
